package hostConn

import (
	"ci-control-backend/common"
	"ci-control-backend/common/httpx"
	"ci-control-backend/model"
	"ci-control-backend/tools"
)

type Info struct {
	Host *model.Host
	Conn *httpx.Context
}

var hostMap = make(map[string]*Info)

func Add(host *model.Host, conn *httpx.Context) {
	hostMap[tools.ToString(host.ID)] = &Info{
		Host: host,
		Conn: conn,
	}

	host.OnlineStatus = common.ONLINE
	host.Update()
}

func Del(host *model.Host) {
	delete(hostMap, tools.ToString(host.ID))
	host.OnlineStatus = common.OFFLINE
	host.Update()
}

func Get(id string) *Info {
	return hostMap[id]
}
